/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : home.js                                 
*  Description  : 클럽개별메인 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-06-20  이윤노    Created.  
*  2012-06-00  이윤노    Complete.  
*******************************************************************************/

jQuery(function($){

	// 동호회 정보
	function clsClubInfoView()
	{
		this._HTMLDom = null;
		this.infoData = null;		
		this._init();
	}
	
	clsClubInfoView.prototype = {
		_init: function(){
			var $layer = $("div#container ul.self_c_name li:eq(0)");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$banner": $("div#container div.self_club_visual")
				, "$view": $("div#container section#main_content div.golf_board div.club_creat table tbody")
			}
		}
		, setData: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$view"];
			
			$layer.find("tr:eq(0) td").html(this.infoData["동호회명"]);
			$layer.find("tr:eq(1) td").html(this.infoData["동호회소개"]);			
			if(this.infoData["가입유형"] == "N"){
				$layer.find("tr:eq(2) td label").html("누구나 가입가능");
				$layer.find("tr:eq(2) td input:text").hide();
			}else {
				$layer.find("tr:eq(2) td label").html("승인 후 가입가능");		
			}
			
			$layer.find("tr:eq(2) td input:text").val(this.infoData["가입질문"]).prop("readonly",true);
			var $txt = this.infoData["키워드"].split(",");
			for(var i=0;i<$txt.length;++i){
				$layer.find("tr:eq(3) td input:text").eq(i).val($txt[i]).prop("readonly",true);				
			}
			$layer.find("tr:eq(4) td").html(this.infoData["카테고리"]["카테고리명"]);			
			$layer.find("tr:eq(6) td img").attr("src", this.infoData["상단스킨"]);
			$layer.find("tr:eq(7) td img").attr("src", this.infoData["배너이미지"]);
			$layer.find("tr:eq(8) td img").attr("src", this.infoData["로고이미지"]);
		}		
	}

	function clsComm()
	{
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			
		}	
	}
	
	function clsControl()
	{
		this.objComm = null;
		
		this.objClubInfo = null
		this.objClubInfoView = null
		this.objRole = null;
				
		this.club_seq = null;
		this.club_my = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			var member_id = _util.getCookie("member_id");
			this.club_seq = _util.getParam("club_seq");
			this.club_my = (_util.getParam("club_my") == "Y") ? 1:0;
			
			if(!this.club_seq) document.location.href = "../club/club.html";
			
			if(!member_id) {
				if(confirm("로그인 후 이용하여 주세요.")){
					_gf.goLogin();						
				}else{
					document.location.href = "../club/club.html";
				}				
			}else if(!this.club_seq) {
				document.location.href = "../club/club.html";
			}
			
			this._preload();
			
			this.objComm = new clsComm();
			this.objClubInfoView = new clsClubInfoView();			
						
			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			_gf.spinStart();
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				
			}
			
			$.ajax({
				url: "js/self_club_top.js"
				, dataType: "script"
				, async: false
				, success: function(){
					
				}
				, error: function(){
					alert("error");
				}
			});
			
			_util.executeThread(function(){
				for(var k in thisClass._permitStart){
					if(!thisClass._permitStart[k]) return false;
				}
				
				return (_clubControl.getClubInfo().infoData);
			}, function(){				
				_gf.spinEnd();;
				thisClass._start();
			});	
		}
		, _role: function(){
			if(!this.objRole.isMember()){
				alert(this.objRole.getError());
				document.location.href="home.html?club_seq="+this.infoData["동호회키"];
			}else if(!this.objRole.isAdmin()){
				alert(this.objRole.getError());
				document.location.href="home.html?club_seq="+this.infoData["동호회키"];
			}
			
			$("body").show();
		}
		, _start: function(){		
			this.objClubInfo = _clubControl.getClubInfo();
			this.objRole = new clsRole(this.objClubInfo.infoData);
			this._role();
			
			this.objClubInfoView.setData(this.objClubInfo.infoData);
		}
		, _bind: function(){
			var thisClass = this;
			
			//수정 버튼 이벤트
			$("p.btn_center img").click(function(event){
				event.preventDefault();				
				document.location.href="club_admin_write.html?club_seq="+ thisClass.club_seq;
			});
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});	